/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
 Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 9/23/2013
Author  : PerTic@n
Company : If You Like This Software,Buy It
Comments: 


Chip type               : ATtiny13
AVR Core Clock frequency: 0.001000 MHz
Memory model            : Tiny
External RAM size       : 0
Data Stack size         : 16
*****************************************************/

#include <tiny13.h>
unsigned char a;
eeprom unsigned char b;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
a=a+128;
TCNT0=0x00;
PORTB.3=0;
PORTB.4=0;
b=a;
}

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Crystal Oscillator division factor: 128
#pragma optsize-
CLKPR=0x80;
CLKPR=0x07;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

// Input/Output Ports initialization
// Port B initialization
// Func5=In Func4=Out Func3=Out Func2=In Func1=In Func0=In 
// State5=T State4=0 State3=0 State2=T State1=T State0=T 
PORTB=0x00;
DDRB=0x18;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 0.016 kHz
// Mode: Normal top=0xFF
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x03;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;

// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Rising Edge
// Interrupt on any change on pins PCINT0-5: Off
GIMSK=0x40;
MCUCR=0x03;
GIFR=0x40;

// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
ACSR=0x80;
ADCSRB=0x00;
DIDR0=0x00;

// ADC initialization
// ADC disabled
ADCSRA=0x00;

// Global enable interrupts
#asm("sei")

a=b;
while (1)
      {
      if(a==0){
      if (TCNT0==0){PORTB.3=1;}
      if (TCNT0==1){PORTB.3=0;}
      if (TCNT0==2){PORTB.3=1;}  
      if (TCNT0==3){PORTB.3=0;}
      if (TCNT0==4){PORTB.3=1;}
      if (TCNT0==5){PORTB.3=0;}
      if (TCNT0==6){PORTB.4=1;}
      if (TCNT0==7){PORTB.4=0;}
      if (TCNT0==8){PORTB.4=1;}
      if (TCNT0==9){PORTB.4=0;}
      if (TCNT0==10){PORTB.4=1;}
      if (TCNT0==11){PORTB.4=0;TCNT0=0xff;}
      }
      if(a==128) 
      { 
      if (TCNT0==0){PORTB.3=1;}
      if (TCNT0==4){PORTB.3=0;}
      if (TCNT0==8){PORTB.3=1;}  
      if (TCNT0==12){PORTB.3=0;}
      if (TCNT0==16){PORTB.3=1;}
      if (TCNT0==20){PORTB.3=0;}
      if (TCNT0==24){PORTB.4=1;}
      if (TCNT0==28){PORTB.4=0;}
      if (TCNT0==32){PORTB.4=1;}
      if (TCNT0==36){PORTB.4=0;}
      if (TCNT0==40){PORTB.4=1;}
      if (TCNT0==44){PORTB.4=0;TCNT0=0xfc;}
     }

      }
}
